package io.sage.modules.query.service.impl;

import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import io.sage.common.utils.PageUtils;
import io.sage.modules.query.dao.QueryMapper;
import io.sage.modules.query.service.QueryService;

@Service
public class QueryServiceImpl implements QueryService {

    @Autowired
    QueryMapper queryMapper;

    @Override
    public PageUtils queryAll(Map<String, Object> params) {
        Integer limit = Integer.valueOf(params.get("limit").toString());
        Integer start = Integer.valueOf(params.get("page").toString());
        Integer page = (start - 1) * limit;
        params.put("page", page);
        List<Map<String, Object>> list = queryMapper.queryAll(params);
        Long count = queryMapper.queryAllCount(params);
        return new PageUtils(list, Integer.valueOf(count.intValue()), limit, start);
    }

    @Override
    public PageUtils queryAlls(Map<String, Object> params) {
        Integer limit = Integer.valueOf(params.get("limit").toString());
        Integer start = Integer.valueOf(params.get("page").toString());
        Integer page = (start - 1) * limit;
        params.put("page", page);
        List<Map<String, Object>> list = queryMapper.queryAlls(params);
        Long count = queryMapper.queryAllsCount(params);
        return new PageUtils(list, Integer.valueOf(count.intValue()), limit, start);
    }
}
